package com.zzyl.task;

import com.zzyl.nursing.service.IReservationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class checkReservationTask {
    @Autowired
    private IReservationService reservationService;

    /**
     * 每小时的第1分钟和第31分钟执行
     * 检查并更新过期的预约状态
     * 预约状态: 0-待报道, 1-已完成, 2-取消, 3-过期
     */
    @Scheduled(cron = "0 1,31 * * * ?")
    public void checkAndUpdateExpiredReservations() {
        try {
            log.info("开始检查过期预约...");
            reservationService.updateReservationStatus();
            log.info("过期预约检查完成");
        } catch (Exception e) {
            log.error("检查过期预约时发生异常", e);
        }
    }
}




